package com.maxuxu.scihome.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @className: UploadFile
 * @author: Maxuxu
 * @date: 2022/7/2 13:42
 * @description: 上传文件的工具类
 */
@Slf4j
@Component
public class UploadFile {

       public String upload(MultipartFile[] file) throws IOException {
           // if (!img.isEmpty()){
           //     String originalFilename = img.getOriginalFilename();
           //     img.transferTo(new File("D:\\test\\upload\\img\\"+originalFilename));
           //     session.setAttribute("pic","图片："+originalFilename+"上传成功！");
           // }
           String path = null;
           String originalFilename = null;
           if (file.length > 0){
               for (MultipartFile fl : file) {
                   if (!fl.isEmpty()) {
                       originalFilename = fl.getOriginalFilename();
                       path = "D:\\test\\file\\"+ originalFilename;
                       fl.transferTo(new File(path));
                   }
               }
           }
           log.error("要修改的用户{}",originalFilename);
           return originalFilename;
       }
}
